package com.ruge._08_springboot_springdata_jpa.controller;

import org.springframework.web.bind.annotation.RestController;

/**
 * 创建人 ：爱丽丝、如歌
 * 创建时间 ：2019-07-02  22:34
 * 描述 ：
 */
@RestController
public class UserController {/*

    @Resource
    private EntityManager entityManager;

    @RequestMapping(value = "list")
    @Transactional
    public Map<String, Object> list() {
        Map<String, Object> map = new HashMap<>();
        UserModel model = new UserModel();
        model.setBirthday(new Date(System.currentTimeMillis()));
        model.setUserName("张三2");
        entityManager.refresh(model);
        return map;
    }

    @RequestMapping(value = "save")
    @Transactional
    public Map<String, Object> save() {
        Map<String, Object> map = new HashMap<>();
        UserModel model = new UserModel();
        model.setBirthday(new Date(System.currentTimeMillis()));
        model.setCreateDate(new Date(System.currentTimeMillis()));
        model.setUserName("张三"+Math.random());
        entityManager.persist(model);
        return map;
    }

    @RequestMapping(value = "findByPK")
    @Transactional
    public Map<String, Object> findByPK() {
        Map<String, Object> map = new HashMap<>();
        UserModel model = entityManager.find(UserModel.class, 1);
        map.put("model",model);
        return map;
    }

    @RequestMapping(value = "remove")
    @Transactional
    public Map<String, Object> remove() {
        Map<String, Object> map = new HashMap<>();
        UserModel model = entityManager.find(UserModel.class, 1);
        entityManager.remove(model);
        return map;
    }

    @RequestMapping(value = "update")
    @Transactional
    public Map<String, Object> update() {
        Map<String, Object> map = new HashMap<>();
        UserModel model = new UserModel();
        model.setId(3);
        model.setUserName("李四");
        entityManager.merge(model);
        return map;
    }
    @RequestMapping(value = "saveManyToOne")
    @Transactional
    public Map<String, Object> testManyToOne(){
        Map<String, Object> map = new HashMap<>();
        UserModel model = new UserModel();
        model.setUserName("王五");
        OrderModel orderModel1 = new OrderModel();
        OrderModel orderModel2 = new OrderModel();
        orderModel1.setName("order 1");
        orderModel2.setName("order 2");
        orderModel1.setUserModel(model);
        orderModel2.setUserModel(model);
        entityManager.persist(model);
        entityManager.persist(orderModel1);
        entityManager.persist(orderModel2);
        return map;
    }
    @RequestMapping(value = "selectManyToOne")
    @Transactional
    public Map<String, Object> testSelectManyToOne(){
        Map<String, Object> map = new HashMap<>();
        OrderModel orderModel = entityManager.find(OrderModel.class, 5);
        System.out.println("订单信息 many to one :"+orderModel);
        map.put("orderModel",orderModel);
        return map;
    }
*/
}
